package com.google.code.swingonfire.utility.date;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;

public class DateRenderInfoDayOfWeekPart extends AbstractStyledDateRenderInfoPart
{

    public DateRenderInfoDayOfWeekPart(int length)
    {
        super(length, determineStyle(length));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getValue(Calendar calendar, DateFormatSymbols dateFormatSymbols, Locale locale)
    {
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

        if (getStyle() == DateRenderInfoStyle.LONG)
        {
            return dateFormatSymbols.getWeekdays()[dayOfWeek];
        }

        return dateFormatSymbols.getShortWeekdays()[dayOfWeek];
    }

    private static DateRenderInfoStyle determineStyle(int length)
    {
        if (length >= 4)
        {
            return DateRenderInfoStyle.LONG;
        }

        return DateRenderInfoStyle.SHORT;
    }

}
